import { defHttp } from '@/utils/http/axios';
import { ErrorMessageMode } from '#/axios';
import { BaseResponse<#if hasPagerResponse?string('true','false')=="true">, PagerResponse</#if> } from '@/api/base';
<#if hasContentType?string('true','false')=="true">
import { ContentTypeEnum } from '@/enums/httpEnum';
</#if>
<#list apiTypes as apiType>
import ${apiType.name} from '@/api/model/${apiType.name}';
</#list>

// 定义接口地址
enum Api {
<#list apiEnums as apiEnum>
  /** ${apiEnum.description} */
  ${apiEnum.name} = '${apiEnum.uri}',
</#list>
}

// 定义接口方法
<#list apiFunctions as apiFunction>
// ${apiFunction.description}
export function ${apiFunction.name}(<#if apiFunction.pathParam?? >${apiFunction.pathParam.name}: ${apiFunction.pathParam.type}, </#if><#if apiFunction.requestParam?? >params: ${apiFunction.requestParam}, </#if>mode: ErrorMessageMode = 'message') {
  return defHttp.${apiFunction.httpMethod}<BaseResponse<${apiFunction.response}>>(
    {
      url: Api.${apiFunction.uriEnum}<#if apiFunction.pathParam?? > + '/' + ${apiFunction.pathParam.name}</#if>,
<#if apiFunction.requestParam?? >
      params,
</#if>
<#if apiFunction.contentType == 'form'>
      headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED },
</#if>
    },
    {
      errorMessageMode: mode,
    },
  );
}
</#list>

// 聚合接口
export default {
<#list apiFunctions as apiFunction>
  ${apiFunction.name},
</#list>
}

